//Joystick

#include<p18F4580.h>
#include <usart.h>

void main()
{
  PORTA = 0xFF;
  TRISAbits.TRISA4 = 1;

  PORTB = 0x00;
  TRISBbits.TRISB0 = 1; 
  TRISBbits.TRISB1 = 0; 
  TRISBbits.TRISB2 = 0; 
  TRISBbits.TRISB3 = 0; 

  while(1)
  {
    if (PORTAbits.RA4 == 0) 
    {
      PORTBbits.RB1 = 1;
      PORTBbits.RB2 = 1;
      PORTBbits.RB3 = 1;
	  TRISC = 0x00;
	  OpenUSART(USART_TX_INT_OFF & 
				USART_RX_INT_OFF & 
				USART_ASYNCH_MODE & 
				USART_EIGHT_BIT &   
				USART_CONT_RX & 
				USART_BRGH_LOW, 25); 
	//baud rate= FOSC / (16 * (spbrg + 1)) 
	//baud rate=   4M / (16 * (25 + 1)) 	= 9600

      putsUSART( "Hello World!" );
      CloseUSART(); 
    }
    else
    {
      PORTBbits.RB1 = 0;
      PORTBbits.RB2 = 0;
      PORTBbits.RB3 = 0;
    }
  }
}